/*
 * 企业认证
 * @Author: ice
 * @Date: 2019-07-12 15:47:32
 * @Last Modified by: ice
 * @Last Modified time: 2019-07-12 18:03:55
 */

<template>
    <div class="container certification-list">
        <div class="operation-wrapper">
            <el-input
                placeholder="请输入开户名称,汇款金额搜索"
                v-model="key"
                size="small"
                @keyup.enter.native="getTableData(1)"
                style="width: 30%;"
            >
                <el-button
                    slot="append"
                    icon="el-icon-search"
                    @click="getTableData(1)"
                />
            </el-input>
        </div>
        <div class="content-wrapper">
            <div class="table-wrapper">
                <el-table
                    :data="tableData"
                    height="100%"
                    style="width: 100%;"
                >
                    <el-table-column
                        fixed="left"
                        header-align="left"
                        align="center"
                        :width="50"
                        label="序号"
                    >
                        <template slot-scope="scope">
                            <div class="table-index">
                                {{ scope.$index + 1 }}
                            </div>
                        </template>
                    </el-table-column>
                    <el-table-column
                        fixed="left"
                        prop="company_name"
                        width="150"
                        show-overflow-tooltip
                        label="开户名称"
                    />
                    <el-table-column
                        prop="bank_name"
                        width="150"
                        show-overflow-tooltip
                        label="开户行名称"
                    />
                    <el-table-column
                        prop="bank_account"
                        width="150"
                        show-overflow-tooltip
                        label="开户账户"
                    />
                    <el-table-column
                        prop="verify_money"
                        width="150"
                        show-overflow-tooltip
                        label="指定汇款金额(元)"
                    />
                    <el-table-column
                        prop="real_money"
                        width="150"
                        show-overflow-tooltip
                        label="实际汇款金额(元)"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        width="180"
                        label="营业执照"
                    >
                        <template slot-scope="scope">
                            <img
                                @click="fnShowPreview(scope.row.business_license)"
                                :src="scope.row.business_license"
                                class="table-image"
                            >
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="first_contract_name"
                        width="150"
                        show-overflow-tooltip
                        label="业务对接人"
                    />
                    <el-table-column
                        prop="first_contract_phone"
                        width="150"
                        show-overflow-tooltip
                        label="手机号"
                    />
                    <el-table-column
                        prop="emergency_contract_name"
                        width="150"
                        show-overflow-tooltip
                        label="创始人"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="emergency_contract_phone"
                        width="150"
                        show-overflow-tooltip
                        label="创始人手机"
                        :formatter="emptyFormatter"
                    />
                    <el-table-column
                        prop="create_time"
                        width="150"
                        label="申请时间"
                    >
                        <template slot-scope="scope">
                            {{ scope.row.create_time*1000 | dateFormatter('yyyy/MM/dd HH:mm') }}
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="status"
                        show-overflow-tooltip
                        label="状态"
                    >
                        <template slot-scope="scope">
                            <template v-if="scope.row.verify == 0">待提交</template>
                            <template v-if="scope.row.verify == 1">待审核</template>
                            <template v-if="scope.row.verify == 2">审核不通过</template>
                            <template v-if="scope.row.verify == 3">审核通过</template>
                        </template>
                    </el-table-column>
                    <el-table-column
                        prop="date"
                        label="操作"
                        fixed="right"
                        :width="150"
                    >
                        <template slot-scope="scope">
                            <div>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify == 3"
                                    @click="fnVerify(scope.row.id, 3)"
                                >通过</el-button>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify == 2"
                                    @click="fnVerify(scope.row.id, 2)"
                                >不通过</el-button>
                                <br>
                                <el-button
                                    type="text"
                                    :disabled="scope.row.verify == 0"
                                    @click="fnSetRealMoney(scope.row.id)"
                                >设置实际汇款金额</el-button>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>
            <div class="pagination-wrapper clearfix">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :total="page.total_count"
                    :page-size="page.page_size"
                    @current-change="getTableData"
                />
            </div>
        </div>
        <img-preview ref="preview" />
    </div>
</template>

<script>
import imgPreview from '@/components/common/img-preview';
export default {
    components: {
        imgPreview
    },
    data() {
        return {
            key: '',
            authResult: {},
            tableData: [],
            filterData: {
                title: ''
            },
            page: {
                now_page: 1,
                total_count: 0,
                page_size: 0
            },
            escape: escape,
            sessionTicket: localStorage.getItem('sessionTicket')
        };
    },
    created() {
        this.authResult = this.$route.meta.authResult;
        this.$store.commit('SET_HEADER', [
            {
                title: "广告系统",
            },
            {
                title: '企业认证管理'
            }
        ]);
        this.getTableData();
    },
    mounted() {
    },
    methods: {
        fnGoMembersList(bid_no) {

        },
        fnChangeBidStatus(id, status) {
            this.$post('/wei4/base%5Cbanner%5Cset_status', {
                id: id,
                status: status == 1 ? 0 : 1
            }, resp => {
                if (resp.code == 1) {
                    this.getTableData(this.page.now_page);
                    this.$message({
                        type: 'success',
                        message: '操作成功',
                        center: true
                    });
                }
            });
        },
        fnComputedText(list) {
            let result = '';

            for (let i = 0; i < list.length; i++) {
                if (result) {
                    result += ',';
                }
                if (list[i] == 1) {
                    result += '登录前';
                }
                if (list[i] == 2) {
                    result += '登录后';
                }
            }
            return result;
        },
        /**
       * 获取表格数据
       */
        getTableData(page) {
            this.$post('/wei4/hire_certification%5Cget_list', {
                page_id: page || this.page.now_page,
                keyword: this.key
            }, resp => {
                if (resp.code == 1) {
                    this.tableData = resp.data.list;
                    this.page.now_page = resp.data.page.now_page;
                    this.page.total_count = resp.data.page.total_count;
                    this.page.page_size = resp.data.page.page_size;
                }
            });
        },

        fnSetRealMoney(id){
            this.$prompt('请输入实际汇款金额(元)', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                inputPattern: /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/,
                inputErrorMessage: '请输入正确的金额'
            }).then(({ value }) => {
                this.$post('/wei4/hire_certification%5Cset_real_money', {
                    id: id,
                    real_money: value,
                }, resp => {
                    if(resp.code == 1){
                        this.getTableData();
                        this.$message({
                            type: 'success',
                            message: '设置成功',
                            center: true
                        });
                    } else {
                        this.$message({
                            type: 'warning',
                            message: resp.msg,
                            center: true
                        });
                    }
                });
            }).catch(() => {
            });
        },

        fnVerify(id, verify){
            if(verify == 3){
                this.$confirm('确认通过认证?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.fnDoVerify(id, verify, '');
                }).catch(() => {
                });
            }else{
                this.$prompt('请输入审核不通过原因', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    inputPattern: /\S/,
                    inputErrorMessage: '请输入审核失败原因'
                }).then(({ value }) => {
                    this.fnDoVerify(id, verify, value);
                }).catch(() => {
                });
            }
        },
        fnDoVerify(id, verify, reason){
            this.$post('/wei4/hire_certification%5Cverify', {
                id: id,
                verify: verify,
                verify_fail_reason: reason
            }, resp => {
                if(resp.code == 1){
                    this.getTableData();
                    this.$message({
                        type: 'success',
                        message: '审核成功',
                        center: true
                    });
                } else {
                    this.$message({
                        type: 'warning',
                        message: resp.msg,
                        center: true
                    });
                }
            });
        },


        /**
       * 列表渲染辅助函数：列表项为空处理
       */
        emptyFormatter(row, column, val) {
            if (!val) {
                return '--';
            }
            return val;
        },
        /**
         * 预览图片
         */
        fnShowPreview(images) {
            this.$refs.preview.show([images]);
        },
    }
};
</script>

<style lang="less" scoped>
  .container {
    display: flex;
    flex-direction: column;
    width: 100%;
  }
  .operation-wrapper {
    display: flex;
    flex-direction: row-reverse;
    padding: 12px 23px;
    background-color: #fff;

    .el-button {
      margin-left: 10px;
    }
  }
  .content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin: 15px;
    overflow: hidden;
  }
  .search-wrapper {
    padding: 15px;
    background-color: #fff;
  }
  .filter-item {
    .el-form-item {
      margin-bottom: 0;
      white-space: nowrap;
    }
    .el-input {
      width: auto;
      vertical-align: middle;
    }
    .el-button {
      margin-left: 15px;
      vertical-align: middle;
    }
  }
  .table-wrapper {
    flex: 1;
    background-color: #fff;
    .table-image {
      width: 150px;
    }
    .table-link {
      color: #409eff;
    }
    .el-button {
      padding: 0;
    }
    .icon-bianji {
      font-size: 14px;
      color: #b9b9b9;
      cursor: pointer;
    }
    .btn-delete {
      color: #fd4d32;
      &.is-disabled {
        color: #c0c4cc;
        cursor: not-allowed;
      }
    }
    .submit-config-item {
      display: inline-block;
      position: relative;
      padding-right: 10px;
      font-size: 14px;

      & + .submit-config-item {
        padding-left: 10px;
        &::before {
          content: "";
          position: absolute;
          top: 50%;
          left: 0;
          width: 1px;
          height: 14px;
          transform: translate(0, -50%);
          background-color: #d8d8d8;
        }
      }

      .num {
        vertical-align: middle;
      }
      .iconfont {
        font-size: 16px;
        color: #b9b9b9;
        vertical-align: middle;
      }

      .icon-tupian {
        font-size: 20px;
      }
    }
  }
  .pagination-wrapper {
    padding-top: 10px;
    .el-pagination {
      float: right;
      padding: 0;
      background-color: transparent;
    }
  }
  .dialog-link {
    & + .dialog-link {
      margin-top: 20px;
    }
    .link-label {
      font-weight: 500;
      margin-right: 20px;
    }
  }
</style>
<style lang="less">
  .certification-list {
    tbody {
      .cell {
        display: flex;
        align-items: center;
        height: 48px;
      }
    }
  }
  .task-list-preview-popover {
    min-width: auto !important;
    width: 120px !important;
    height: 120px;
    padding: 8px !important;
  }
  .sort-dialog {
    width: 270px !important;
  }
</style>
